<?php

class WebUser extends CWebUser {

	protected $_userInfo = NULL;
	protected $_userInfoRefreshed = FALSE;

	public function getUserInfo($key = NULL, $refresh = true) {
		if ($refresh == false) {
			if (is_null($this->_userInfo)) {
				$this->_userInfo = $this->getState("detail");
			}
		}
		if ($refresh == true || is_null($this->_userInfo) ) {
			if (! $this->_userInfoRefreshed) {
				$arrIdentityStates = $this->getState("id");
				if (isset($arrIdentityStates["id"])) {
					$one = One::model()->findByPk($arrIdentityStates["id"]);
					if ($one instanceof One) {
						$this->_userInfo = $one->getDetail();
					}
				}
			}
		}
		if (is_null($this->_userInfo)) {
			throw new CException(Yii::t('System','Cannot load user Information from database.'));
		}
		if (is_null($key)) {
			return $this->_userInfo;
		} else {
			return $this->_userInfo[$key];
		}
	}
}
